package system;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

public class PeopleSystem {
    static Scanner sc = new Scanner(System.in);
    public static Deque<People> list = new LinkedList<>();
    static {
        list.add(new People("陈昊",420983188808267433L,"男","随州"));
        list.add(new People("梁状",421381198403145271L,"男","荆州"));
        list.add(new People("郭宸希",422222198611056318L,"男","武汉"));
    }
    public static void main(String[] args) {
        while (true) {
            System.out.println("------公民身份管理系统-------");
            System.out.println("1.信息录入");
            System.out.println("2.信息查询");
            System.out.println("3.信息修改");
            System.out.println("4.信息删除");
            System.out.println("5.退出");
            System.out.println("-------------------------");
            System.out.println("请输入您的选择：");
            switch (sc.nextInt()) {
                case 1:
                    add();
                    break;
                case 2:
                    query();
                    break;
                case 3:
                    update();
                    break;
                case 4:
                    delete();
                    break;
                case 5:
                    System.out.println("退出系统");
                    System.exit(0);
                default:
                    System.out.println("请输入正确的选项");
            }
        }
    }
    //信息录入
    public static void add() {
        System.out.println("请输入姓名：");
        String name = sc.next();
        System.out.println("请输入身份证：");
        long idcard = sc.nextLong();
        System.out.println("请输入性别：");
        String sex = sc.next();
        System.out.println("请输入住址：");
        String address = sc.next();
        list.add(new People(name,idcard,sex,address));
    }
    //2.信息查询
    public static void query() {

        System.out.println("姓名\t\t身份证\t\t性别\t地址");
        for (People people : list) {
                System.out.println(people);
        }
    }
    //3.信息修改
    public static void update() {
        System.out.println("请输入要修改的姓名：");
        String name = sc.next();
        boolean flag = false;
        for (People people : list) {
            if (people.getName().equals(name)) {
                System.out.println("请输入新的姓名：");
                String newName = sc.next();
                System.out.println("请输入新的身份证：");
                long newIdcard = sc.nextLong();
                System.out.println("请输入新的性别：");
                String newSex = sc.next();
                System.out.println("请输入新的地址：");
                String newAddress = sc.next();

                System.out.println("修改成功");
                flag = true;
            }
        }
        if (!flag){
            System.out.println("没有找到" + name + "的信息");
        }
    }
    //4.信息删除
    public static void delete() {
        System.out.println("请输入要删除的姓名：");
        String name = sc.next();
        list.removeIf(people -> people.getName().equals(name));
        System.out.println("删除成功");
    }
}